package com.lanxiao.cloud.common.web.bus.listener;

import com.google.common.eventbus.Subscribe;
import com.lanxiao.cloud.common.web.bus.event.LogEvent;
import com.lanxiao.cloud.common.web.bus.event.LogEventPublisher;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2021-09-26
 */
@Component
public class LogEventListener {

  private final StreamBridge streamBridge;

  public LogEventListener(LogEventPublisher publisher,
      StreamBridge streamBridge) {
    this.streamBridge = streamBridge;
    publisher.register(this);
  }

  @Subscribe
  public void logEvent(LogEvent<Long> event) {
    streamBridge.send("logCollectEvent-out-0", MessageBuilder
        .withPayload(event)
        .build());
  }

}
